package com.milo.coding.syncronized;

/**
 * @Auther milo
 * @Description syncronized测试
 * @Date 2021-05-06 10:49
 */
public class MSynchronizedTest {
    public static void main(String[] args){
        // 线程使用同一个对象

        // 同时使用同一个对象锁
        //共用对象
        MSynchronized mSynchronized = new MSynchronized();

        Thread s1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
//                    System.out.println("=========我是线程1==========");
                    mSynchronized.method4("我是线程4");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
        Thread s2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
//                    System.out.println("==========我是线程2========");
                    mSynchronized.method5("我是线程5");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });

        //启动
        s1.start();
        s2.start();
    }
}
